#ifndef BARREL_DETECTOR_HPP
#define BARREL_DETECTOR_HPP

#include "detector_base.hpp"
#include <geometry_msgs/msg/point_stamped.hpp>
#include <pcl/common/centroid.h>
#include <sensor_msgs/msg/point_cloud2.hpp>
#include <rclcpp/publisher.hpp>


namespace center_detection{

    struct BarrelDetectionParams
    {
        float search_start_z = 0.5f;
        float search_end_z = 0.1f;
        float search_step = 0.01f;
        int min_points_in_slice = 30;
        float barrel_height = 0.55f;
        float barrel_radius = 0.2f;

        float fixed_point_a_x = 0.2f;
        float fixed_point_a_y = 0.2f;

    };

    class BarrelDetector : public DetectorBase {

    public:

        BarrelDetector();
        ~BarrelDetector() = default;

        bool detectCenter(PointCloud cloud, geometry_msgs::msg::PointStamped& center_point) override;

        void setParameters(rclcpp::Node* node) override;


    private:
        
        BarrelDetectionParams params_;

        PointCloud extractRingCloud(const PointCloud& cloud, float& detected_z);

        pcl::PointCloud<pcl::PointXYZI>::Ptr projectToXY(const PointCloud& cloud);

        bool calculateCenter(const PointCloud& cloud, float& center_x, float& center_y);


    };
    
}

#endif